#coding:UTF8

import tkinter as tk
import matplotlib
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import os


def line(file=os.path.dirname(os.path.dirname(os.getcwd()))+'\\data\\score.txt'):
    matplotlib.use('TkAgg') #不知道啥意思
    root =tk.Tk()
    root.title("散点图")
    
    poslist = []
    neglist = []
    fopen = open(file,'r')
    for i in fopen:
        poslist.append(float(i.split(' ')[0]))
        neglist.append(float(i.split(' ')[1]))
    
    #设置图形尺寸与质量
    f =Figure(figsize=(5,4), dpi=100) #figsize画布的大小长*宽
    a = f.add_subplot(1,1,1) #第一个参数*第二个参数=子图总个数，第三个参数为当前子图位置

    #绘制图形
    a.plot(poslist,'bo')
    
    #把绘制的图形显示到tkinter窗口上
    canvas =FigureCanvasTkAgg(f, root)
    canvas.show()
    canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
    #把matplotlib绘制图形的导航工具栏显示到tkinter窗口上
    toolbar =NavigationToolbar2TkAgg(canvas, root)
    toolbar.update()
    canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)

    #按钮单击事件处理函数
    def _quit():
        #结束事件主循环，并销毁应用程序窗口
        root.quit()
        root.destroy()
        
    button =tk.Button(root, text='Quit', command=_quit)
    button.pack(side=tk.BOTTOM)
    root.mainloop() 